package com.fire.security.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;


//验证码工具kaptcha的配置类
@Configuration
public class CaptchaConfig {
    @Bean(name = "captchaProducer")
    public DefaultKaptcha getKaptchaBean(){
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        Properties properties = new Properties();
        //是否有边框，默认为true，我们可以自己设置yes
        properties.setProperty("kaptcha.border","yes");
        //边框颜色
        properties.setProperty("kaptcha.border.color","105,179,90");
        //验证码字符颜色
        properties.setProperty("kaptcha.textproducer.font.color","blue");
        //验证码图片宽度，默认200
        properties.setProperty("kaptcha.image.width","120");
        //高度
        properties.setProperty("kaptcha.image.height","40");
        //文本字符大小
        properties.setProperty("kaptcha.textproducer.font.size","32");
        //KAPTCHA_SESSION_KEY
        properties.setProperty("kaptcha.session.key","kaptchaCode");
        //文本字符间距
        properties.setProperty("kaptcha.textproducer.char.space","4");
        //文本字符长度
        properties.setProperty("kaptcha.textproducer.char.length","4");
        //文本字符样式
        properties.setProperty("kaptcha.textproducer.font.names","Arial,Courier");
        //噪点颜色
        properties.setProperty("kaptcha.noise.color","gray");
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }

}
